package com.qfedu.service;

import com.qfedu.dao.SingerDao;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.Singer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SingerServiceImpl implements SingerService{

    @Autowired
    private SingerDao singerDao;

    /**
     * 获取所有歌手
     * @return
     */
    @Override
    public List<Singer> getAllSinger() {

        List<Singer> singerList = singerDao.getAllSinger();

        if (singerList != null && singerList.size() > 0){

            return singerList;
        }
        return null;
    }

    /**
     * 通过性别对歌手分类
     * @param sex
     * @return
     */
    @Override
    public List<Singer> getSingerOfSex(byte sex) {

        List<Singer> singerList = singerDao.getSingerOfSex(sex);

        if (singerList != null && singerList.size() > 0){

            return singerList;
        }
        return null;
    }









    /**
     * 添加歌手
     * @param singer
     * @return
     */
    @Override
    public ResponseData<String> addSinger(Singer singer) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = singerDao.addSinger(singer);
        if (result) {
            responseData.setCode(1);
        } else {
            responseData.setCode(0);
        }

        return responseData;

    }


    /**
     * 更新歌手
     * @param singer
     * @return
     */



    /**
     * 删除歌手
     * @param id
     * @return
     */
    @Override
    public ResponseData<String> deleteSingerById(int id) {

        ResponseData<String> responseData = new ResponseData<>();
        boolean result = singerDao.deleteSinger(id);
        if (result) {
            responseData.setCode(1);
        }
        return responseData;
    }

    @Override
    public ResponseData<String> updateSinger(Singer singer) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = singerDao.updateSinger(singer);
        if (result) {
            responseData.setCode(1);
        }
        return responseData;
    }

    @Override
    public ResponseData<String> updateAvator(Singer singer) {

        ResponseData<String> responseData = new ResponseData<>();
        boolean result = singerDao.updateAvator(singer);
        System.out.println("result = " + result);
        if (result) {
            responseData.setCode(1);
        }
        return responseData;
    }


}
